package jkadx.MPrimeFinder;

import java.util.Random;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class TestMPrimeFinder
{
    static int MAGICNUMBER = 2; // it's 2 because lower bound and upperbound are two ints

    @Test
    public void InsertBoundsIntoPayloadTest()
    {
        Random rand = new Random();
        byte[] payload = new byte[MAGICNUMBER * (Integer.SIZE / Byte.SIZE)];
        int[] result = new int[MAGICNUMBER];
        int lowerbound;
        int upperbound;


        for (int i = 2000000; i > 0; --i)
        {          
            lowerbound = rand.nextInt();
            upperbound = rand.nextInt();

            int[] boundsrange = {lowerbound, upperbound};
            MPrimeFinder.insertBoundsIntoPayload(boundsrange, payload);
            result = MPrimeFinder.bytesToInts(payload);
          
            assertEquals("Failed match #1", lowerbound, result[0]);
            assertEquals("Failed match #2", upperbound, result[1]);
        }
    }


    public static void main(String[] args)
    {
	org.junit.runner.JUnitCore.main(TestMPrimeFinder.class.getName());
    }
}